package cn.kgc.springboot.http;

import lombok.Data;

import java.util.HashMap;

//code:状态码 message:请求结果的描述 data:响应数据
@Data//lombook
public class ResponseResult {
    private Integer code;
    private String message;
    private HashMap<String,Object> data=new HashMap<>();//了解
    //业务操作成功
    public static ResponseResult success(){
        ResponseResult responseResult =new ResponseResult();
        responseResult.setCode(0);
        responseResult.setMessage("操作成功");
        return responseResult;
    }

    //业务添加失败
    public static ResponseResult fail(){
        ResponseResult responseResult =new ResponseResult();
        responseResult.setCode(110);
        responseResult.setMessage("操作失败");
        return responseResult;
    }


    //程序有异常
    public static ResponseResult error(){
        ResponseResult responseResult =new ResponseResult();
        responseResult.setCode(500);
        responseResult.setMessage("程序异常...");
        return responseResult;
    }

    //设置响应结果的数据
    public ResponseResult data(String key,Object value){
        this.data.put(key, value);
        return this;
    }

}
